package com.wang.config;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.HashMap;
import java.util.Map;
@RestControllerAdvice
public class ShiroException {

    /**
     * 登录认证异常     *
     * @return
     */
    @ExceptionHandler({ UnauthenticatedException.class, AuthenticationException.class })
    public Object authenticationException() {

        Map<String, Object> map = new HashMap<>();
        map.put("code", "-1000");
        map.put("message", "未登录");
        return map;
    }

    /**
     * 权限异常
     * @return
     */
    @ExceptionHandler(AuthorizationException.class)
    public Object authorizationException (){
        //return "抱歉您没有权限访问该内容! no per";
        Map<String, Object> map = new HashMap<>();
        map.put("code", "-1001");
        map.put("message", "无权限");
      //  return "Sorry you don't have permission to access this content";
        return map;
    }

    @ExceptionHandler(Exception.class)
    public String handleException(Exception e){
       // return "系统异常! system error ";
        System.out.println(e.toString());
        return "system error 22222! ";
    }

}